package cn.ekuma.epos.security.dao;


import e.odbo.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.security.db.table.I_ChildPermission;
import cn.ekuma.security.impl.ChildPermission;
import cn.ekuma.security.impl.Permission;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class ChildPermissionDAO extends ModifiedLogDAO<ChildPermission>{

	public ChildPermissionDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                    "CHILDPERMISSION",
                    new Field[]{
                       new Field(I_ChildPermission.ID,Datas.STRING, Formats.STRING),
                       new Field(I_ChildPermission.BASESECURITYNAME,Datas.STRING, Formats.STRING),
                       new Field(I_ChildPermission.PARENTSECURITYNAME,Datas.STRING, Formats.STRING),
                       new Field(I_ChildPermission.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP)  
                     },
                    new int[]{0}
                    );
    }

    @Override
    public void writeInsertValues(DataWrite dp, ChildPermission obj) throws BasicException {
        dp.setString(1,obj.getKey());
        dp.setString(2,obj.getBaseSecurityName());
        dp.setString(3,obj.getParentSecurityName());
        dp.setTimestamp(4,obj.getLastModified());
        
    }

    @Override
    public Class getSuportClass() {
       return Permission.class;
    }

    public ChildPermission readValues(DataRead dr,ChildPermission obj) throws BasicException {
        if(obj==null)
    	  obj=new ChildPermission();
        obj.setKey(dr.getString(1));
        obj.setBaseSecurityName(dr.getString(2));
        obj.setParentSecurityName(dr.getString(3));
        obj.setLastModified(dr.getTimestamp(4));
       
        return obj;
    }

	

	public boolean hasePermissionByRole(String roleId, String modeName,
			String permission,String subPermission) {
		// TODO Auto-generated method stub
		return false;
	}
	
}
